import dictApi from '@/api/dict'
export default{
    data(){
        return{
            dictCount:0,
            dictQuery:{
                page:0,
                pageSize:20,
                zdmc:''
            },
            dicts:[]
        }
    },
    created(){
        this.loadDicts();
    },
    methods:{
        loadDicts(){
            this.loading = true;
            dictApi.queryDict(this.dictQuery)
            .then(response => {
                const { data } = response;
                if( data.error_code == 0 ){
                    
                    this.dicts = data.list;
                    this.dictCount = data.totalCount;
                }else{
                }
                this.loading = false;
            }).catch(error => {
                this.loading = false;
            });
        },
        onAddDict(){
            this.$refs.dictForm.show({})
            .then((action)=>{
                if( action === 'ok'){
                    this.loadDicts();
                }
            });
        },
        onEditDict(row){
            this.$refs.dictForm.show(row)
            .then((action)=>{
                if( action === 'ok'){
                    this.loadDicts();
                }
            });
        },
        onDeleteDict(row){
            this.$confirm('是否删除该字典？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                closeOnClickModal:false
            }).then((action) => {
                this.deleteDict(row);
            }).catch((action) => {
            });
        },
        deleteDict(row){
            const ids = []
            ids.push(row.zdzj)
            dictApi.delDict(ids)
            .then(response => {
                const { data } = response;
                if(data.error_code == 0){
                    this.loadDicts();
                    if(this.dictRow && row.zdzj == this.dictRow.zdzj){
                        this.row = null;
                        this.details = [];
                    }
                    this.showInfo("操作成功！");
                }else{
                    this.showError("操作失败！");
                }
            }).catch(error => {
                this.showError("操作失败！");
            });
        },
        onQueryDict(){
            this.loadDicts();
            this.dictRow = null;
            this.details = [];
        },
        onClearQueryDict(){
            this.dictQuery.zdmc = "";
        },
        onDictPageChange(obj){
            this.dictQuery.pageSize = obj.pageSize;
            this.dictQuery.page = obj.currentPage;
            this.loadDicts();
            this.dictRow = null;
            this.details = [];
        },
        zdjgFormater(row,column){
            return row.zdjg==0?'否':'是';
        }
    }
}